package com.kalman.common;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 集合类
 * @author kalman03
 */
public class CollectionUtils {

	private final static String[] EMPTY_ARRAY_STRING = new String[0];

	private final static Integer[] EMPTY_ARRAY_INTEGER = new Integer[0];

	private final static Long[] EMPTY_ARRAY_LONG = new Long[0];

	public static final boolean isEmpty(Collection<?> c) {
		return null == c || c.isEmpty();
	}

	public static final boolean isNotEmpty(Collection<?> c) {
		return ! CollectionUtils.isEmpty(c);
	}
	
	public static final boolean isNotEmpty(Map<?,?> map) {
		return map !=null && map.size() >0;
	}
	
	public static final boolean isEmpty(Map<?,?> map) {
		return !isNotEmpty(map);
	}
	
	public static final String[] toStringArray(List<?> list) {
		if (CollectionUtils.isEmpty(list)) {
			return new String[0];
		}
		return (String[]) list.toArray(new String[list.size()]);
	}

	public static final Integer[] toIntegerArray(List<?> list) {
		if (CollectionUtils.isEmpty(list)) {
			return EMPTY_ARRAY_INTEGER;
		}
		return (Integer[]) list.toArray(new Integer[list.size()]);
	}

	public static final Long[] toLongArray(List<?> list) {
		if (CollectionUtils.isEmpty(list)) {
			return EMPTY_ARRAY_LONG;
		}
		return (Long[]) list.toArray(new Long[list.size()]);
	}

	public static final String[] toStringArray(Set<?> set) {
		if (CollectionUtils.isEmpty(set)) {
			return EMPTY_ARRAY_STRING;
		}
		return (String[]) set.toArray(new String[set.size()]);
	}

	public static final Integer[] toIntegerArray(Set<?> set) {
		if (CollectionUtils.isEmpty(set)) {
			return EMPTY_ARRAY_INTEGER;
		}
		return (Integer[]) set.toArray(new Integer[set.size()]);
	}

	public static final Long[] toLongArray(Set<?> set) {
		if (CollectionUtils.isEmpty(set)) {
			return EMPTY_ARRAY_LONG;
		}
		return (Long[]) set.toArray(new Long[set.size()]);
	}

}
